#include "InputHandler.h"

InputHandler::InputHandler()
{
	m_sName = "";
	m_bOn = true;
	m_hWnd = RenderManager::getSingleton()->getWindowsHandle();
	OIS::ParamList pl;
	pl.insert(OIS::ParamList::value_type("WINDOW", Ogre::StringConverter::toString(m_hWnd)));

	m_pInputMgr= OIS::InputManager::createInputSystem(pl);
	m_pMouse = static_cast<OIS::Mouse*>(m_pInputMgr->createInputObject( OIS::OISMouse, true) );
	m_pKeyboard = static_cast<OIS::Keyboard*>(m_pInputMgr->createInputObject( OIS::OISKeyboard, true) );
	//m_pJoystick = static_cast<OIS::JoyStick*>(m_pInputMgr->createInputObject( OIS::OISJoyStick, true) );
	m_pMouse->setEventCallback(this);
	m_pKeyboard->setEventCallback(this);
	//m_pJoystick->setEventCallback(this);

	InputManager::getSingleton()->ManageInputHandler(this);
}


InputHandler::InputHandler(string name)
{
	m_sName = name;
	m_bOn = true;
	m_hWnd = RenderManager::getSingleton()->getWindowsHandle();
	OIS::ParamList pl;
	pl.insert(OIS::ParamList::value_type("WINDOW", Ogre::StringConverter::toString(m_hWnd)));

	m_pInputMgr= OIS::InputManager::createInputSystem(pl);
	m_pMouse = static_cast<OIS::Mouse*>(m_pInputMgr->createInputObject( OIS::OISMouse, true) );
	m_pKeyboard = static_cast<OIS::Keyboard*>(m_pInputMgr->createInputObject( OIS::OISKeyboard, true) );
	m_pJoystick = static_cast<OIS::JoyStick*>(m_pInputMgr->createInputObject( OIS::OISJoyStick, true) );
	m_pMouse->setEventCallback(this);
	m_pKeyboard->setEventCallback(this);
	m_pJoystick->setEventCallback(this);

	InputManager::getSingleton()->ManageInputHandler(this);
}

InputHandler::~InputHandler()
{
	if(m_pMouse)
		delete m_pMouse;
	if(m_pKeyboard)
		delete m_pKeyboard;
	OIS::InputManager::destroyInputSystem(m_pInputMgr);
}

void InputHandler::capture()
{
	if(m_bOn)
	{
		m_pKeyboard->capture();
		m_pMouse->capture();
		//m_pJoystick->capture();
	}
}